package com.gwtjs.icustom.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * {@link http://localhost:8080/swagger-ui.html#/.}
 * @author flash
 *
 */
@Configuration
@EnableSwagger2
public class Swagger2 {
	
	@Value("${spring.application.name}")
    private String appName;
	@Value("${spring.contBasePath.swagger2}")
    private String contBasePath;
	
	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage(contBasePath)).paths(PathSelectors.any())
				.build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title(appName+" Swagger2 RESTful APIs").description("仅用于开发环境")
				.termsOfServiceUrl("http://").contact(appName).version("1.0").build();
	}
}
